<template>
    <table class="table-bordered" border="1">
        <tr>
            <td>用户名</td>
            <td><input v-model="info.name" type="text"/></td>
        </tr>
        <tr>
            <td>密码</td>
            <td><input v-model="info.pwd" type="password"></td>
        </tr>
        <tr>
            <td colspan="2"><input type="button" @click="logins"value="登录" class="btn btn-success"></td>
        </tr>
    </table>
    </template>
    <script setup lang="ts">
    import { ref } from 'vue';

    import { useRouter } from 'vue-router';

    const router=useRouter();
    
    import axios from 'axios';
    
    const info=ref({
        name:"",
        pwd:""
    })
    const logins=()=>{
    axios({
        url:"https://localhost:44366/api/Drom/Logain",
        params:{
            name:info.value.name,
            pwd:info.value.pwd
        },
        method:"get"
    }).then(res=>{
        if(res.data.RM_Id==1){
            alert(res.data.RM_Msg);
            
        }else if(res.data.RM_Id==2){
            alert(res.data.RM_Msg);
            
        }else if(res.data.RM_Id==0){
            alert(res.data.RM_Msg);
            uindo(res.data.RM_Date[0].UserLoginId)

           
        }
    })
    .catch(err=>{
            console.log(err);
        })
    }
    const uindo=(udi:string)=>{
    axios({
        url:"https://localhost:44366/api/Drom/Search",
        method:"get",
        params:{
            uid:udi
        }
    }).then(res=>{
        if(res.data>0){
            alert('用户信息已完善')
            if(res.data[0].UsersInforId==1){
                router.push('/UUsers')
            }else{
                router.push('/GUsers')
            }
            return
        }else{
            
            router.push({
                name:'UsersInfor',
                params:{
                    uid:udi
                }
                })
            
        }
    })
    .catch(err=>{
            console.log(err);
    })
}
    </script>